<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增获奖名单')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-prize-add">
            <input id="curDeptId" name="curDeptId" type="hidden" th:value="${curDeptId}"   />
            <input id="schoolId" name="schoolId" type="hidden"   />
            <input id="facultyId" name="facultyId" type="hidden"  />
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">学校：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" onclick="selectSchool()" id="school" name="school" readonly="true" th:value="${school?.deptName}" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">院系：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" onclick="selectFaculty()" id="faculty" name="faculty" readonly="true" th:value="${faculty?.deptName}" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">大赛名称：</label>
                <div class="col-sm-8">
                    <select id="gameId" name="gameId" class="form-control" th:with="games=${games}" required>
                        <option th:each="game : ${games}" th:text="${game.name}" th:value="${game.id}"></option>
                    </select>
                </div>
            </div>
            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label  is-required">作品类别：</label>-->
            <!--                <div class="col-sm-8">-->
            <!--                    <select name="categoryId" class="form-control" th:with="categorys=${@actCategoryService.selectAll()}" required>-->
            <!--                        <option th:each="category : ${categorys}" th:text="${category.name}" th:value="${category.id}"></option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">作品类别：</label>
                <div class="col-sm-8">
                    <select class="form-control" id="categoryId" name="categoryId" required>
                        <option value="">-- 请选择 --</option>
                        <block  th:each="category : ${categoryTree}">
                            <block th:if="${#lists.isEmpty(category.children)}">
                                <option  th:text="${category.name}" th:value="${category.id}"></option>
                            </block>
                            <block th:if="not ${#lists.isEmpty(category.children)}">
                                <optgroup th:label="${category.name}">
                                    <block  th:each="child : ${category.children}">
                                        <option  th:text="${child.name}" th:value="${child.id}"></option>
                                    </block>
                                </optgroup>
                            </block>
                        </block>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">命题名称：</label>
                <div class="col-sm-8">
                    <select id="titleId" name="titleId" class="form-control" th:with="titles=${actTitles}" required>
                        <option value="">-- 请选择 --</option>
                        <th:block th:each="title : ${titles}">
                            <option  th:text="${title.title}" th:value="${title.id}"></option>
                        </th:block>
                        <!--                        <option th:each="title : ${titles}" th:text="${title.title}" th:value="${title.id}"></option>-->
                    </select>
                </div>
            </div>


            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label  is-required">命题名称：</label>-->
            <!--                <div class="col-sm-8">-->
            <!--                    <textarea name="title" class="form-control" required></textarea>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">参赛编号：</label>
                <div class="col-sm-8">
                    <input name="actNo" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">作品名称：</label>
                <div class="col-sm-8">
                    <textarea name="actName" class="form-control" required></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">作者：</label>
                <div class="col-sm-8">
                    <input name="author" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">作者电话：</label>
                <div class="col-sm-8">
                    <input name="authorPhone" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">指导老师：</label>
                <div class="col-sm-8">
                    <input name="teacher" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">指导老师电话：</label>
                <div class="col-sm-8">
                    <input name="teacherPhone" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">专业：</label>
                <div class="col-sm-8">
                    <input name="major" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">其他：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">获奖等级：</label>
                <div class="col-sm-8">
                    <select id="prizeLevel" name="prizeLevel" class="form-control" required>
                        <option value="">-- 请选择 --</option>
                        <option value="一等奖">一等奖</option>
                        <option value="二等奖">二等奖</option>
                        <option value="三等奖">三等奖</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">报送全国总评审：</label>
                <div class="col-sm-8">
                    <select id="sendAudit" name="sendAudit" class="form-control" required>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        $(function(){
            $("#gameId").change(function(){
                changeTitle();
            })

            $("#categoryId").change(function(){
                changeTitle();
            })
        })

        function changeTitle(){
            var gameId = $("#gameId").val();
            var categoryId =  $("#categoryId").val();
            $.post(ctx + "system/title/selectByGameIdAndCategoryId?gameId=" + gameId + "&categoryId=" + categoryId,{},
                function(response){
                    $("#titleId").html("<option value=''>-- 请选择命题 --</option>")//清空下拉框
                    var result = response.data;
                    console.log(response)
                    for (var i = 0; i < result.length; i++) {
                        var option = $("<option></option>").text(result[i].title);
                        option.attr("value", result[i].id);
                        $("#titleId").append(option);
                    }
                });
        }

        var prefix = ctx + "system/prize"
        $("#form-prize-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-prize-add').serialize());
            }
        }

        /*选择学校-选择父部门树*/
        function selectSchool() {
            var curDeptId = $("#curDeptId").val();
            var prefix = ctx + "system/dept";
            var options = {
                title: '学校选择',
                width: "380",
                url: prefix + "/selectDeptTree/" + curDeptId,
                callBack: doSubmitSchool
            };
            $.modal.openOptions(options);
        }

        function doSubmitSchool(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#schoolId").val(body.find('#treeId').val());
            $("#school").val(body.find('#treeName').val());
            $.modal.close(index);
        }


        /*选择院系-选择父部门树*/
        function selectFaculty() {
            var hasPermission = $("#hasPermission").val();;
            //if(hasPermission == 'false'){return;}
            var curDeptId = $("#curDeptId").val();
            var prefix = ctx + "system/dept";
            var options = {
                title: '院系选择',
                width: "380",
                url: prefix + "/selectDeptTree/" + curDeptId,
                callBack: doSubmitFaculty
            };
            $.modal.openOptions(options);
        }

        function doSubmitFaculty(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#facultyId").val(body.find('#treeId').val());
            $("#faculty").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>
